<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="stylesheets/bootstrap.min.css">
    <link rel="stylesheet" href="./stylesheets/reset.css">
    <style>
        #logo {
            margin-top: 60px;
            position: relative;
            margin-left: 16.666%;
        }

        #logo ul {
            position: absolute;
            left: 35%;
            top: 30px;

        }

        #logo li {
            float: left;
            font-size: 20px;
        }

        #list1 {
            width: 100%;

        }

        #list1 table {
            width: 70%;
            margin-left: 16.666%;
            border-top: 1px #ccc;
            text-align: left;
            border: 1px solid #ccc;
            margin-top: 10px;
            margin-bottom: 30px;
            text-align: center;
        }

        #list1 table td {
            height: 80px;
            border: none;
            border-top: 1px solid #ccc;
            overflow: hidden;
        }

        #list1 table th {
            background: #ccc;
            height: 40px;
            text-align: center;
        }

        #list1 table img {
            width: 100px;
        }

        .xunzhong,
        #inpHeader {
            width: 20px;
            height: 20px;

        }

        .jian,
        .jia {
            width: 20px;
            height: 15px;
            border: 1px solid #ccc;
            position: relative;
            top: 2px;
            line-height: 15px;
        }

        #tiaozhuan {
            background: #f08200;
            padding: 2px 5px;
            border-radius: 5px;
        }
    </style>
</head>

<body>
    <!-- 头部 -->
    <div id="lxcbox">
        <div id="lxcheader"></div>
    </div>


    <div id="logo">
        <img src="./images/lxc/logo.png" alt="">
        <ul>
            <li style="color: #f08200;margin-left:200px ;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </li>
            <li>&nbsp;&nbsp;确认订单消息&nbsp;&nbsp;&nbsp;></li>
            <li>&nbsp;&nbsp;订单提交成功</li>
        </ul>
    </div>
    <strong style="margin-left:16.666% ; margin-top: 30px; display: block;">购物车</strong>
    <div id="list1">
        <table>
            <tr>
                <th style="width: 50px;"><input type="checkbox" id="inpHeader"></th>
                <th style="width: 100px;">爱果果的水果店</th>
                <th style="width: 100px;">库存</th>
                <th style="width: 100px;">单价</th>
                <th style="width: 100px;">数量</th>
                <th style="width: 100px;">金额</th>
                <th style="width: 100px;">操作</th>
            </tr>
            <tr id="jine">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td>商品金额 <strong id="zhongjine1">0</strong></td>

            </tr>
            <tr>
                <td id="quanxuan" style="color: red;">全选</td>
                <td id="piliangdel">批量删除</td>
                <td></td>
                <td></td>
                <td></td>
                <td colspan="2">商品金额 <strong>￥<span id="zhongjine"></span></strong><input type="button" name=""
                        id="tiaozhuan" value="立即购买">
                </td>

            </tr>
        </table>

    </div>
    <!-- 尾部 -->
    <div id="lxcfooter">
        <div id="lxcfooter1"></div>
        <div id="lxcfooter2"></div>
        <div id="lxcbottom"></div>
    </div>
    <div id="myModal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog"
        aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
            </div>
        </div>
    </div>
</body>

</html>

<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="./javascripts/bootstrap.min.js"></script>
<script src="./javascripts/lxcheader.js"></script>
<script>
    //ajax请求
    {

        //添加到 #jine前面
        $.ajax({
            type: "post",
            url: "/lxcgouwuche/biao",
            data: {
                goodId: localStorage.userID

            },
            dataType: "json",
            success: function (response) {
                console.log(response);
                
                for (let i = 0; i < response.length; i++) {
                    var pp = $('<tr>').insertBefore('#jine');
                    var t1 = $('<td>').appendTo(pp);
                    var t2 = $('<td>').appendTo(pp);
                    var t3 = $('<td>').appendTo(pp).html(response[i].car_zl);
                    var t4 = $('<td>').appendTo(pp).addClass('danjia').html('￥');
                    var t5 = $('<td>').appendTo(pp);
                    var t6 = $('<td>').appendTo(pp).addClass('jiaqian').html('￥');
                    var t7 = $('<td>').appendTo(pp).addClass('del').html('删除');
                    $('<input type="checkbox" class="xunzhong ">').appendTo(t1);

                    $('<img>').appendTo(t2).attr({
                        src: response[i].car_img,
                    });
                    $('<span>').appendTo(t2).html(response[i].car_name).css({
                        display: 'inline-block',
                        width: '20px',
                        height: '80px'
                    });
                    $('<span>').appendTo(t4).html(response[i].car_price);
                    $('<input type="button" value="-" class="jian">').appendTo(t5);
                    $('<span>').appendTo(t5).html(1);
                    $('<input type="button" value="+" class="jia">').appendTo(t5);
                    $('<span>').appendTo(t6).html(response[i].car_price);

                }
                jisuan();

            }
        });
    }





    function jisuan(){
          { //表操作
        //加减法
        $("#quanxuan").click(function (e) {
            $('.xunzhong').prop('checked', 'checked');
            $('#inpHeader').prop('checked', 'checked')
        });

        $('#inpHeader').click(function (e) {
            if ($('#inpHeader').prop('checked') == false) {
                $('.xunzhong').prop('checked', false);
            } else {
                $('.xunzhong').prop('checked', 'checked');
            }
        });

        $(".xunzhong").click(function (e) {
            for (var p = 0; p < $('.xunzhong').length; p++) {
                if ($('.xunzhong').eq(p).prop('checked') == false) {
                    $('#inpHeader').prop('checked', false);
                    return;
                } else {
                    $('#inpHeader').prop('checked', true)
                }
            }

        });
   


        $("#piliangdel").click(function (e) {

            if ($('#inpHeader').prop('checked') == true) {
                $('#inpHeader').parent().parent().parent().remove();
            } else {
                $('.xunzhong').each(function (i, v) {
                    if ($(this).prop('checked') == true) {
                        $(this).parent('tr').remove();
                    }
                })

            }

        });

        $('.jian').click(function (e) {
            thit = this;
            var offset = $(this).siblings('span');
            var shuliang = Number($(offset).html());
            if (shuliang < 1) {
                shuliang = 1;
            }
            $(offset).html(shuliang -= 1);
            jiaqian(thit, shuliang);
        });
        $('.jia').click(function (e) {
            thit = this;
            var offset = $(this).siblings('span');
            var shuliang = Number($(offset).html());
            $(offset).html(shuliang += 1);
            jiaqian(thit, shuliang);
        });

        function jiaqian(thit, shuliang) {
            var dj = parseFloat($(thit).parent().siblings('.danjia').children('span').html());
            var zj = $(thit).parent().siblings('.jiaqian').children('span');
            $(zj).html(dj * shuliang);
            zjq(zj);
        }

        function zjq(zj) {

            var arr = 0;
            $(".jiaqian span").each(function (i, v) {
                console.log(parseFloat($(this).html()));

                arr += parseFloat($(this).html());
                console.log(arr);
            });


            $("#zhongjine").html(arr);
            $("#zhongjine1").html(arr);

        }
        $(".del").click(function (e) {
            $(this).parent().remove();


        });
    }

    }
  
    {
        $('#tiaozhuan').click(function (e) {
            e.preventDefault();
            window.location.href = '/lxcshangjiabupeisong';
        });
    }
</script>